package org.lib.dbpoolhello.config;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.druid.support.http.StatViewServlet;

/**
 * Druid配置
 * @author ben
 * @date 2021-09-28 21:56:47 CST
 */
@Configuration
public class DruidConfig {

	/**
	 * 添加 /druid/* 端点
	 * @author ben
	 * @date 2021-09-28 22:05:44 CST
	 * @return
	 */
	@Bean
	public ServletRegistrationBean statViewServlet( ) {
		// 创建Servlet注册实体
		ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(
				new StatViewServlet(), "/druid/*");
		
		// 设置IP白名单：本机
		servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
		
		// 控制台管理用户
		servletRegistrationBean.addInitParameter("loginUsername", "root");
		servletRegistrationBean.addInitParameter("loginPassword", "root");
		
		// 是否可以重置数据
		servletRegistrationBean.addInitParameter("resetEnable", "false");
		
		return servletRegistrationBean;
	}
	
}
